
const cloud = require('wx-server-sdk')
// var request = require('request')
var request = require('request-promise');

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {

  let access_token = event.access_token
  let file_path = event.file_path
  let dbname = event.dbname

  let options = {
    method: 'POST',
    url: "https://api.weixin.qq.com/tcb/databasemigrateimport?access_token=" + access_token,
    body: {
      "env": "test-02qyq",
      "collection_name": dbname,
      "file_path": file_path,
      "file_type": 1,
      "stop_on_error": false,
      "conflict_mode": 2
    },
    json: true
  }
  let res = await request(options)
  return res
}